import copy from './copy';
import { permission, role } from './permission';
import { setupTdesignTools } from './tdesign';
import { isUrl } from '@/utils/is';
import { formatDate, formatDateTime } from '@/utils/date.js';
import { baseURL } from '@/config/modules/network';

const baseFile = (url) => {
	if (!(typeof url === 'undefined')) {
		if (isUrl(url)) return url;
		else return baseURL + '/' + url;
	}
};

/**
 * 注册全局自定义指令
 * @param {*} app
 */
export function setupDirective(app) {
	// 权限控制
	app.directive('permission', permission);
	// 角色控制
	app.directive('role', role);
	// 复制
	app.directive('copy', copy);

	setupTdesignTools(app);

	app.config.globalProperties.formatDate = window.formatDate = (date, format) => formatDate(date, format);
	app.config.globalProperties.formatDateTime = window.formatDateTime = (date, format) => formatDateTime(date, format);
	app.config.globalProperties.baseFile = window.baseFile = (url) => baseFile(url);
}
